import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'dart:async';

Future showDurationDialog(String content, {Widget? child}) {
  return Get.defaultDialog(
      barrierDismissible: false,
      title: "",
      content: Column(
        children: [
          Text(
            content,
            style: TextStyle(fontWeight: FontWeight.bold),
          ),
          SizedBox(
            height: 10,
          ),
          Container(
            alignment: Alignment.center,
            width: 220,
            height: 100,
            child: Column(
              children: [
                CircularProgressIndicator(),
                child == null
                    ? Text("")
                    : Padding(
                        padding: const EdgeInsets.only(top: 20),
                        child: child,
                      ),
              ],
            ),
          )
        ],
      ));
}

Future showDurationDialog30s(String content, {Widget? child}) async {
  // 创建对话框并获取关闭控制器
  final dialog = Get.defaultDialog(
    barrierDismissible: false,
    title: "",
    content: Column(
      children: [
        Text(
          content,
          style: TextStyle(fontWeight: FontWeight.bold),
        ),
        const SizedBox(height: 10),
        Container(
          alignment: Alignment.center,
          width: 220,
          height: 100,
          child: Column(
            children: [
              const CircularProgressIndicator(),
              if (child != null)
                Padding(
                  padding: const EdgeInsets.only(top: 20),
                  child: child,
                ),
            ],
          ),
        )
      ],
    ),
  );

  // 设置30秒后自动关闭
  Future.delayed(const Duration(seconds: 30), () {
    if (Get.isDialogOpen == true) {
      Get.back();
    }
  });

  // 返回对话框的Future
  return dialog;
}
